﻿#region CREDIT & LICENSE
/*******************************************
 * CREDIT: 
 * http://www.ROMPROS.com 
 * Tremendously helpful website, also would
 * like to give special thanks to:
 * 
 * Roverser - for the great effort on a c repository 
 * that most of this was ported from. http://code.google.com/p/rombot/
 * 
 * ROMeo - for the great amount of information shared
 * all across the rompros site. http://www.rompros.com/member.php?u=1901
 * 
 * 
 * LICENSE:
 *  
 * RomAPI is c# library is used to communicate directly with
 * the Runes Of Magic game client. 
 * 
 * Copyright (C) 2010  digitalxarts@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *******************************************/
#endregion

using System.Collections;
using System.Linq;
using Magic;

namespace RoMFramework.RomAPI
{
	public static class RomClientManager
	{
	    static RomClientManager()
		{
            Refresh();
		}

	    public static ArrayList Clients { get; private set; }

	    public static void Refresh()
        {
            //this is a more reliable way to find the processes. credit - ROMeo...
            int[] processList = SProcess.GetProcessesFromClassname(Common.ROM_WINDOW_CLASS_NAME);
            Clients = new ArrayList();
            foreach (int process in processList.Where(RomClient.CanAttachToProcess))
            {
                Clients.Add(new RomClient(process));
            }
        }
        public static RomClient GetClientByPlayerName(string playerName)
        {
            return Clients.Cast<RomClient>().FirstOrDefault(client => client.Player.Name == playerName);
        }
	}
    
    

}
